package com.example.blog.controller;

import com.example.blog.data.UpblogPram;
import com.example.blog.data.UserInfoPram;
import com.example.blog.pojo.response.BlogInfoResponse;
import com.example.blog.pojo.resquest.AddBlogResqust;
import com.example.blog.service.impl.BlogServiceImpl;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/Blog")
public class BlogController {
    @Resource(name = "BlogService")
    private BlogServiceImpl blogServiceImpl;
    @RequestMapping("/getlist")
    public List<BlogInfoResponse> getlist(){
        return blogServiceImpl.getlist();
    }

    @RequestMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull(message = "用户id不能为空") Integer blogId){
        return blogServiceImpl.getBlogDetail(blogId);
    }

    @RequestMapping("/addBlog")
    public Boolean addBlog(@Validated @RequestBody AddBlogResqust addBlogResqust){
        log.info("addBlog 接收参数:",addBlogResqust);
        return blogServiceImpl.addBlog(addBlogResqust);
    }

    @RequestMapping("/updateBlog")
    public Boolean updateBlog(@Validated @RequestBody UpblogPram upblogPram){
        log.info("updateBlog 参数:",upblogPram);
        return blogServiceImpl.updateBlog(upblogPram);
    }

    /**
     *
     * @param blogId
     * @return
     */
    @RequestMapping("/deteleBlog")
    public Boolean detele(Integer blogId){
        log.info("deteleBlog参数:",blogId);
        return blogServiceImpl.deteleBlog(blogId);
    }

}
